package com.platform.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.platform.comm.validation.groups.Insert;
import com.platform.comm.dto.BaseQo;
import com.platform.comm.enums.YnEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * Description: 字典项DTO
 *
 * @author libin Created on 2019/7/17
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class DictItemQo extends BaseQo {

    private static final long serialVersionUID = -3980014069724547180L;
    /**
     * 字典值
     */
    @NotEmpty(message = "字典值不能为空", groups = Insert.class)
    @Size(max = 50, message = "字典值最多50个字符")
    private String itemCode;

    /**
     * 字典中文值
     */
    @NotEmpty(message = "字典中文值不能为空", groups = Insert.class)
    @Size(max = 50, message = "字典中文值最多128个字符")
    private String itemName;

    /**
     * 字典组ID
     */
    @NotEmpty(message = "字典组不能为空", groups = Insert.class)
    private String groupId;

    /**
     * 排序编号
     */
    @Min(value = 0)
    private Integer sortNum;

    /**
     * 信息状态
     */
    @JsonIgnore
    @Pattern(regexp = "[01YN]", message = "信息状态不合法")
    private YnEnum delFlag;

    @Override
    public void init() {
        super.init();
        if (this.getSortNum() == null) {
            this.setSortNum(0);
        }
        this.setDelFlag(YnEnum.N);
    }
}
